using System;

namespace SBPweb.Forge.Common.Diagnostics
{
	/// <summary>
	/// Class of MeasuredInterval.
	/// </summary>
    public class MeasuredInterval
    {
		/// <summary>
		/// Local variable of the start time
		/// </summary>
        protected DateTime start;

		/// <summary>
		/// Constructor of the MeasuredInterval. Starts automatically.
		/// </summary>
        public MeasuredInterval()
            : this(true)
        {
        }

		/// <summary>
		/// Contructor of the MeasuredInterval
		/// </summary>
		/// <param name="autoStart">Starts automatically?</param>
        public MeasuredInterval(bool autoStart)
        {
            if (autoStart)
            {
                Start();
            }
        }

		/// <summary>
		/// Start the time
		/// </summary>
		/// <returns></returns>
        public DateTime Start()
        {
            return start = DateTime.Now;
        }

		/// <summary>
		/// Stop the time
		/// </summary>
		/// <returns></returns>
        public TimeSpan Stop()
        {
            return DateTime.Now.Subtract(start);
        }
    }
}
